import router from "@/router";
import { ElLoading } from 'element-plus';
import NProgress from "@/utils/nprogress";



let loading: any = null;
// 路由前钩子显示 loading
router.beforeEach((to, from, next) => {
    NProgress.start();

    loading = ElLoading.service({
        lock: true,
        text: '页面加载中...',
        background: 'rgba(0, 0, 0, 0.4)'
    });
    next();

});

// 路由后钩子关闭 loading
router.afterEach(() => {
    NProgress.done();

    setTimeout(() => {
        loading?.close();
        loading = null;
    }, 300); // 延迟关闭更自然
});